# -*- coding: utf-8 -*-
import scrapy
import json

class ProductSpider(scrapy.Spider):
    name = "product"
    allowed_domains = ["http://m.17dutyfree.com"]
    start_urls = ['http://http://m.17dutyfree.com/']
    brand_url = 'http://m.17dutyfree.com/brand/' #'http://m.17dutyfree.com/brand/30?format=json&p=1'
    product_url = 'http://m.17dutyfree.com/product/'
    brand_idx_array = range(1,39)
    
    def start_requests(self):
        for brand_idx in self.brand_idx_array:
            base_url = self.brand_url+repr(brand_idx)+'?format=json&p='
            for page in range(1, 30):
                url = base_url + repr(page)
                yield scrapy.Request(url=url, callback=self.parse_brand)
            
    def parse_brand(self, response):
        js = json.loads(response.body_as_unicode()) 
        if len(js)<2:
            yield {}
        else:
            for item in js:
                yield item

    def parse_item(self, response):
        pass
    def pass_price(self, response):
        for data in response.xpath('//*[@id="product-page"]/li[1]/div/div').css('p::text').extract():
            pass
            
